/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.etfbl.net.dao;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author abosancic
 */
public class ClassGeneratorUtil {
    
     /**
     * Returns the given underscored_word_group as a Human Readable Word Group.
     * (Underscores are replaced by spaces and capitalized following words.)
     *
     * @param pWord String to be made more readable
     * @return Human-readable string
     */
    public static String humanizeToGetterAndSetter(String pWord) {
        StringBuilder sb = new StringBuilder();
        String[] words = pWord.replaceAll("_", " ").split("\\s");
        for (int i = 0; i < words.length; i++) {
            if (words[i].length() > 0) {
                sb.append(Character.toUpperCase(words[i].charAt(0)));
                if (words[i].length() > 1) {
                    sb.append(words[i].substring(1)/*.toLowerCase()*/);
                }
            }
        }
        return sb.toString();
    }
    
    /**
     * Returns the given user_id as a getUserId.
     * (Underscores are replaced by spaces and capitalized following words.)
     *
     * @param pWord String to be made more readable
     * @return Human-readable string
     */
    public static String humanizeToGetter(String pWord) {
        return "get" + humanizeToGetterAndSetter(pWord);
    }
    
    /**
     * Returns the given user_id as a setUserId.
     * (Underscores are replaced by spaces and capitalized following words.)
     *
     * @param pWord String to be made more readable
     * @return Human-readable string
     */
    public static String humanizeToSetter(String pWord) {
        return "set" + humanizeToGetterAndSetter(pWord);
    }
    
    /**
     * Returns the given underscored_word_group as a Human Readable Word Group.
     * (Underscores are replaced by spaces and capitalized following words.)
     *
     * @param pWord String to be made more readable
     * @return Human-readable string
     */
    public static String humanizeToField(String pWord) {
        StringBuilder sb = new StringBuilder();
        pWord = humanizeToGetterAndSetter(pWord);
         if (pWord.length() > 0) {
                sb.append(Character.toLowerCase(pWord.charAt(0)));
                if (pWord.length() > 1) {
                    sb.append(pWord.substring(1));
                } 
            }
         String field = sb.toString();
         if(reservedWords.contains(field))
             return field + field.charAt(0);
        return sb.toString(); 
    }
    
     /**
     * Returns the given underscored_word_group as a Human Readable Word Group.
     * (Underscores are replaced by spaces and capitalized following words.)
     *
     * @param pWord String to be made more readable
     * @return Human-readable string
     */
    public static String humanize(String pWord) {
        StringBuilder sb = new StringBuilder();
        String[] words = pWord.replaceAll("_", " ").split("\\s");
        for (int i = 0; i < words.length; i++) {
            if (words[i].length() > 0) {
                sb.append(Character.toUpperCase(words[i].charAt(0)));
                if (words[i].length() > 1) {
                    sb.append(words[i].substring(1));
                }
            }
        }
        return sb.toString();
    }
    
    public static List<String> reservedWords = Arrays.asList(new String[]{"abstract", "assert", "boolean", "break", "byte", "case",
                "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends",
                "false", "final", "finally", "float", "for", "goto", "if", "implements",
                "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public",
                "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this",
                "throw", "throws", "transient", "true", "try", "void", "volatile", "while"});
    
}
